package com.json;

import java.util.*;

import com.alibaba.fastjson.*;
import com.domain.Test;

public class ListJson {
		
	public static void main(String[] args) {
		List<Test> tlist = new ArrayList<Test>();
		Test t = new Test();
		t.setName("123");
		t.setSex("10");
		tlist.add(t);
		
		t = new Test();
		t.setName("456");
		t.setSex("11");
		tlist.add(t);
		JSONArray json2 =JSONArray.parseArray(JSON.toJSONString(tlist));
		System.out.println(json2);
		
		for(int i= 0;i<json2.size();i++){
			JSONObject b = (JSONObject) json2.get(i);
			
			System.out.println(b);
			System.out.println(b.getString("sex"));
		}
		
		t = new Test();
		t.setName("789");
		t.setSex("13");
		tlist.add(0,t);
		json2 =JSONArray.parseArray(JSON.toJSONString(tlist));
		System.out.println(json2);
		
		for(int i= 0;i<json2.size();i++){
			JSONObject b = (JSONObject) json2.get(i);
			
			System.out.println(b);
			System.out.println(b.getString("sex"));
		}
		
		
		t = new Test();
		t.setName("777");
		t.setSex("14");
		tlist.add(0,t);
		json2 =JSONArray.parseArray(JSON.toJSONString(tlist));
		System.out.println(json2);
		
		for(int i= 0;i<json2.size();i++){
			JSONObject b = (JSONObject) json2.get(i);
			
			// System.out.println(b);
			System.out.println(b.getString("sex"));
		}
		
		
	}
	
	
	
}
